package com.example.xd.phone_album

import android.content.Context
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder

/**
 * @auther XuDan on 2020/9/8.
 */
class PictureAdapter(context: Context, layoutResId: Int, data: MutableList<SingleImageModel>?) :
    BaseQuickAdapter<SingleImageModel, BaseViewHolder>(layoutResId, data) {
    var context: Context = context
    override fun convert(holder: BaseViewHolder, item: SingleImageModel) {
        val img = holder.getView<ImageView>(R.id.recycler_item_img)
        val tv = holder.getView<TextView>(R.id.recycler_item_tv_select)
        val img_shader = holder.getView<ImageView>(R.id.recycler_item_img_shader)
        val lp = img.layoutParams
        lp.width = getScreenWidth(context) / 4
        lp.height = getScreenWidth(context) / 4
        img.layoutParams = lp
        if (holder.position == 0) {
            Glide.with(context).load(R.mipmap.icon_camera).into(img)
            tv.visibility = View.GONE
        } else {
            tv.visibility = View.VISIBLE
            holder.addOnClickListener(R.id.recycler_item_tv_select)
            Glide.with(context).load(item?.path).into(img)
            if (item.isSelect) {
                img_shader.setBackgroundColor(context.getColor(R.color.color_gray))
                tv.background = context.getDrawable(R.drawable.circle_solid)
                tv.setText(item.ordinal.toString())
            } else {
                img_shader.setBackgroundColor(context.getColor(R.color.color_transparention))
                tv.background = context.getDrawable(R.drawable.circle_empty)
                tv.setText("")
            }
        }
    }
}